package com.cfpl.admin_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfpl.admin_service.service.VegetableManagementService;
import com.cfpl.project_common.enums.CodeEnum;
import com.cfpl.project_common.exception.BusException;
import com.cfpl.project_common.pojo.VegetableManagement;
import com.cfpl.admin_service.mapper.VegetableManagementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 14720
* @description 针对表【vegetable_management(果蔬管理表)】的数据库操作Service实现
* @createDate 2023-10-10 11:09:53
*/
@Service
public class VegetableManagementServiceImpl extends ServiceImpl<VegetableManagementMapper, VegetableManagement>
    implements VegetableManagementService {

    @Autowired
    private VegetableManagementMapper vegManMapper;
    /**
     * 分页查询果蔬管理对象
     * @param currentPage 当前页
     * @param pageSize 每页条数
     * @param condition 查询条件 模糊查询
     * @return
     */
    @Override
    public Page<VegetableManagement> querypage(int currentPage, int pageSize, String condition) {
        LambdaQueryWrapper<VegetableManagement> queryWrapper = new LambdaQueryWrapper<>();
        if (condition != null) {
            queryWrapper.eq(VegetableManagement::getClassification,condition);
        }
        return vegManMapper.selectPage(new Page<>(currentPage,pageSize),queryWrapper);
    }
    /**
     * 添加一条果蔬管理对象
     * @param vegMan 果蔬管理对象
     */
    @Override
    public void addVegMan(VegetableManagement vegMan) {
        vegManMapper.insert(vegMan);
    }
    /**
     * 查询一条果蔬管理对象
     * @param id 果蔬管理ID
     * @return 果蔬管理对象
     */
    @Override
    public VegetableManagement queryVegManById(Long id) {
        return vegManMapper.selectById(id);
    }
    /**
     * 根据ID删除果蔬管理对象
     * @param id 果蔬管理id
     */
    @Override
    public void removeVegManById(Long id) {
        vegManMapper.deleteById(id);
    }
    /**
     * 更新一条果蔬管理对象
     * @param vegMan 新的果蔬管理
     */
    @Override
    public void updateVegMan(VegetableManagement vegMan) {
        vegManMapper.updateById(vegMan);
    }
    /**
     * 批量删除果蔬管理对象
     * @param Ids  农果蔬管理id列表
     */
    @Override
    public void deleteBatchByIds(List<Long> Ids) {
        if (Ids == null || Ids.size() < 1) {
            throw new BusException(CodeEnum.PARAMETER_ERROR);
        }
        vegManMapper.deleteBatchIds(Ids);
    }
}




